package com.hclc.impl.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hclc.entity.model.BaseSmsTemplateModel;
import com.hclc.api.base.IBaseSmsTemplateService;
import com.hclc.mapper.base.BaseSmsTemplateMapper;
import com.hclc.util.json.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * <p>短信模板表 服务实现类 </p>
 * @author lx(1309244704@qq.com)
 * @since 2019-08-28
 */
@Service("baseSmsTemplateService")
public class BaseSmsTemplateServiceImpl extends ServiceImpl<BaseSmsTemplateMapper, BaseSmsTemplateModel> implements IBaseSmsTemplateService {

	private static Logger _logger = LoggerFactory.getLogger(BaseSmsTemplateServiceImpl.class);

		private @Autowired
        BaseSmsTemplateMapper baseSmsTemplateMapper;

	/** 查询状态并分页 */
	@Override
	public IPage<BaseSmsTemplateModel> getPage(Page<BaseSmsTemplateModel> page, Map<String, Object> map)  {
		IPage<BaseSmsTemplateModel> resultPage = baseSmsTemplateMapper.selectPage(page, new QueryWrapper<BaseSmsTemplateModel>().allEq(map, false));
		return resultPage;
	}

	/** 查询model*/
	@Override
	public BaseSmsTemplateModel getModel(BaseSmsTemplateModel model)  {
		QueryWrapper<BaseSmsTemplateModel> queryWrapper = new QueryWrapper<BaseSmsTemplateModel>(model);
		return baseSmsTemplateMapper.selectOne(queryWrapper);
	}

	/** 插入 */
	@Transactional
	@Override
	public void addBaseSmsTemplate(BaseSmsTemplateModel model)  {
		Assert.notNull(model, "model is null");
		_logger.debug("BaseSmsTemplateModel = {}", JsonUtil.toJson(model));
		baseSmsTemplateMapper.insert(model);
	}

	/** 修改 */
	@Transactional
	@Override
	public void modBaseSmsTemplate(BaseSmsTemplateModel model)  {
		Assert.notNull(model, "model is null");
		_logger.debug("BaseSmsTemplateModel = {}", JsonUtil.toJson(model));
		baseSmsTemplateMapper.updateById(model);
	}

	/** 删除状态（物理删除） */
	@Transactional
	@Override
	public void del(Long id) {
		Assert.notNull(id, "id is null");
		_logger.debug("id = {}", id);
		baseSmsTemplateMapper.deleteById(id);
	}

}
